package the_third_chapter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class ShiTi {

	public static void main(String[] args) {
	
		String Question = generateQuestion();
		String[] list = Question.split(",");
		int a = Integer.parseInt(list[0]);
		int b = Integer.parseInt(list[1]);
		String s =  list[2];
		boolean isRight = checkRes(a,b,s);
		if(isRight){
			System.out.println("答对了!");
		}else{
			System.out.println("答错了！");
		}
	}
	public static String generateQuestion(){
		Scanner input = new Scanner(System.in);

		int a, b, c;
		a = (int) (Math.random() * 10 + Math.floor(Math.random() * 10) * 10);
		b = (int) (Math.random() * 10 + Math.floor(Math.random() * 10) * 10);
		String s = generateCharacter();
		
		if(s.equals("+")){
			while(a+b > 100){
				return generateQuestion();
			}
		}
		if (s.equals("-")) {
			if (a < b) {
				int temp = a;
				a = b;
				b = temp;
			}
		}
		System.out.println("请计算下面的题目：");
		System.out.println(a + " " + s + " " + b + " =");
		return a + "," + b +"," + s;
	}
	
	public static boolean checkRes(int a, int b, String s){
		int result;
		if (s.equals("+")) {
			result = a + b;
		} else {
			result = a - b;
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			s = br.readLine();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		int res = Integer.parseInt(s);
		if (result == res) {
			return true;
		} else {
			return false;
		}
	}

	public static String generateCharacter() {
		Random random = new Random();
		int d = random.nextInt(10);
		if (d > 5) {
			return "+";
		} else {
			return "-";
		}
	}
}
